package com.jprocms.module.cms.api;

import com.jpro.framework.common.pojo.CommonResult;
import com.jprocms.module.cms.framework.cache.CacheService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import static com.jpro.framework.common.pojo.CommonResult.success;
import static com.jprocms.module.cms.dal.redis.RedisKeyConstants.CONFIG_UPDATE_TIME;

@RestController
@Validated
public class ConfigNotifyApiImpl implements ConfigNotifyApi {
    @Resource
    private CacheService cacheService;

    @Override
    public CommonResult<Boolean> updateConfigForApi() {
        //通过更新redis时间，各个实例定时检查内存对象和redis的时间，如果redis有更新则取拉取否则跳过，没有才有消息队列是为了节省消息队列的部署
        cacheService.setCacheObject(CONFIG_UPDATE_TIME, System.currentTimeMillis());
        return success(true);
    }
}
